#include "levelOrderBottom.h"
vector<vector<int>> levelOrderBottom(TreeNode* root)
{
    vector<vector<int>> result;
    if (!root)
        return result;
    else
    {
        stack<vector<int>> into;
        queue<TreeNode*> req;
        req.push(root);
        while (!req.empty())
        {
            int numNode = req.size();
            vector<int> layer;
            for (int i = 0; i < numNode; i++)
            {
                TreeNode* current = req.front();
                req.pop();
                layer.push_back(current->val);

                if (current->left)
                    req.push(current->left);
                if (current->right)
                    req.push(current->right);
            }
            into.push(layer);
        }
        while (!into.empty())
        {
            result.push_back(into.top());
            into.pop();
        }
        return result;
    }
}